package com.itheima.config;

import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;


@Component
public class RestHighLevelClientConfig {

    /**
     * 初始化配置
     */
    @Bean
    public RestHighLevelClient init() {
        RestHighLevelClient restClientBuilder = new RestHighLevelClient(
                RestClient.builder(new HttpHost("192.168.200.129", 9200, "http"))
                        //修改请求配置构建器
                        .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
                            @Override
                            public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
                                return builder
                                        .setConnectTimeout(10000)  //设置连接超时时间（默认1秒）
                                        .setSocketTimeout(60000);  //设置socket超时时间（默认为30秒）
                            }
                        }));
        return restClientBuilder;
    }

}
